export const COMPLETE = 0;
export const SUCCESS = 1;
export const FAILURE = SUCCESS << 1;
export const RUNNING = FAILURE << 1;
export const FINISHED = RUNNING << 1;
export const ERROR = FINISHED << 4;

export function createUUID() {
    var s = [];
    let hexDigits = "0123456789abcdef";
    for (var i = 0; i < 36; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
    }
    // bits 12-15 of the time_hi_and_version field to 0010
    s[14] = "4";

    // bits 6-7 of the clock_seq_hi_and_reserved to 01
    s[19] = hexDigits.substr((s[19].charCodeAt(0) & 0x3) | 0x8, 1);

    s[8] = s[13] = s[18] = s[23] = "-";

    var uuid = s.join("");
    return uuid;
}

const NAME_COMPLETE = `[COMPLETE]`
const NAME_SUCCESS = `[SUCCESS]`
const NAME_FAILURE = `[FAILURE]`
const NAME_RUNNING = `[RUNNING]`
const NAME_FINISHED = `[FINISHED]`
const NAME_ERROR = `[ERROR]`
const NAME_UNKNOW = `[UNKNOW]`

export function statusName(status: number) {
    switch (status) {
        case COMPLETE: {
            return NAME_COMPLETE
        }
        case SUCCESS: {
            return NAME_SUCCESS
        }
        case FAILURE: {
            return NAME_FAILURE
        }
        case RUNNING: {
            return NAME_RUNNING
        }
        case FINISHED: {
            return NAME_FINISHED
        }
        case ERROR: {
            return NAME_ERROR
        }
        default: {
            return NAME_UNKNOW
        }
    }
}

export const KEY_MEM_RUNNING_CHILD = 'runningChild';
export const KEY_MEM_CALLED_CHILD = 'calledChild';
